package com.xzz.string;

/**
 * @author: hhz
 * @create: 2022-02-25 14:02
 * 537. 复数乘法
 **/
public class ComplexNumberMultiply {
    public static void main(String[] args) {
        System.out.println(complexNumberMultiply("1+1i","1+-2i"));
    }
    public static String complexNumberMultiply(String num1, String num2) {
        String[] s1 = num1.split("\\+|i");
        String[] s2 = num2.split("\\+|i");
        int a = Integer.parseInt(s1[0]);
        int b = Integer.parseInt(s1[1]);
        int c = Integer.parseInt(s2[0]);
        int d = Integer.parseInt(s2[1]);
        int A = a*c-b*d;
        int B = b*c+a*d;
        return A+"+"+B+"i";


    }
}
